//just test the vga_sync module
//time:2015-11-13 23:33:40
//by:fengshuai
//

module vga_test(
                    input   wire            sys_clk,
                    input   wire            sys_rst_n,
                    output  wire            hsync,
                    output  wire            vsync,
						  output  wire            video_en, 
                    output  wire    [2:0]   rgb,
						  output	 reg				  led
                );

parameter	BLACK = 0;
parameter	BLUE = 1;
parameter	GREEN = 2;
parameter	DIAN	= 3;
parameter	RED = 4;
parameter	PURPLE = 5;
parameter	YELLOW = 6;
parameter	WHITE = 7;
					 
wire    [9:0]   pixel_x;
wire    [9:0]   pixel_y;
wire 	          clk_25mhz;
reg	 [2:0]rgb_reg;
/*
always @ (posedge clk_25mhz or negedge sys_rst_n)
    if(!sys_rst_n)
        begin
            rgb_reg <= 3'b0;
        end 
    else
	 begin				//显示八色彩条
			if(pixel_y < 240)
				begin
					if(pixel_x < 10'd80)
						rgb_reg = BLACK;
					else if(pixel_x < 10'd160)
						rgb_reg = BLUE;     		
					else if(pixel_x < 10'd240)
						rgb_reg = GREEN;	 			
					else if(pixel_x < 10'd320)
						rgb_reg = DIAN;		
					else if(pixel_x < 10'd400)
						rgb_reg = RED;				
					else if(pixel_x < 10'd480)
						rgb_reg = PURPLE;					
					else if(pixel_x < 10'd560)
						rgb_reg = YELLOW;			
					else	
						rgb_reg = WHITE;   
				end 
			else
			begin
				if(pixel_x < 10'd80)
						rgb_reg = WHITE;
					else if(pixel_x < 10'd160)
						rgb_reg = YELLOW;     		
					else if(pixel_x < 10'd240)
						rgb_reg = PURPLE;	 			
					else if(pixel_x < 10'd320)
						rgb_reg = RED;		
					else if(pixel_x < 10'd400)
						rgb_reg = DIAN;				
					else if(pixel_x < 10'd480)
						rgb_reg = GREEN;					
					else if(pixel_x < 10'd560)
						rgb_reg = BLUE;			
					else	
						rgb_reg = BLACK;   
			end 
	end
*/	
	
reg		[23:0] dispay;
reg		[23:0] cnt;
always @(posedge clk_25mhz or negedge sys_rst_n)
	if(!sys_rst_n)
		begin
			dispay <= 24'b000_001_010_011_100_101_110_111;
			cnt <= 0;
			led <= 0;
		end 
	else
		begin
			cnt <= cnt + 1'b1;
			if(cnt == 24'd12500000)
				begin 
					cnt <= 24'b0;
					led <= ~led;
					dispay <= {dispay[2:0],dispay[23:3]};
				end 
		end 
always @ (posedge clk_25mhz or negedge sys_rst_n)
    if(!sys_rst_n)
        begin
            rgb_reg <= 3'b0;
        end 
    else
	 begin				//显示八色彩条
			if(pixel_y < 240)
				begin
					if(pixel_x < 10'd80)
						rgb_reg = dispay[2:0];
					else if(pixel_x < 10'd160)
						rgb_reg = dispay[5:3];     		
					else if(pixel_x < 10'd240)
						rgb_reg = dispay[8:6];	 			
					else if(pixel_x < 10'd320)
						rgb_reg = dispay[11:9];		
					else if(pixel_x < 10'd400)
						rgb_reg = dispay[14:12];				
					else if(pixel_x < 10'd480)
						rgb_reg = dispay[17:15];					
					else if(pixel_x < 10'd560)
						rgb_reg = dispay[20:18];			
					else	
						rgb_reg = dispay[23:21];   
				end 
			else
			begin
				if(pixel_x < 10'd80)
						rgb_reg = dispay[23:21];
					else if(pixel_x < 10'd160)
						rgb_reg = dispay[20:18];     		
					else if(pixel_x < 10'd240)
						rgb_reg = dispay[17:15];	 			
					else if(pixel_x < 10'd320)
						rgb_reg = dispay[14:12];		
					else if(pixel_x < 10'd400)
						rgb_reg = dispay[11:9];				
					else if(pixel_x < 10'd480)
						rgb_reg = dispay[8:6];					
					else if(pixel_x < 10'd560)
						rgb_reg = dispay[5:3];			
					else	
						rgb_reg = dispay[2:0];   
			end 
	end		
	
	
assign rgb = (video_en == 1'b1) ? rgb_reg:3'b0;


pll_25mhz	pll_25mhz_inst (
	.inclk0 ( sys_clk ),
	.c0 ( clk_25mhz )
	);

vga_sync vga_syn_inst(
            .clk            (clk_25mhz),
            .rst_n          (sys_rst_n),
            .video_en       (video_en),
            .hsync          (hsync),
            .vsync          (vsync),
            .pixel_x        (pixel_x),
            .pixel_y        (pixel_y)
                       
        );

endmodule